﻿using ElectronicShoppingMall.Service.Data;
using ElectronicShoppingMall.Service.Models.Enterprise;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElectronicShoppingMall.Service.Services.Enterprise
{
    public class OperationLogService :IDisposable
    {
        private readonly ElectronicShoppingMallContext data;
        public OperationLogService()
        {
            data = new ElectronicShoppingMallContext();
        }

        public void CreateLog(AdminLogModel adminLog)
        {
            var employee = data.Employees.SingleOrDefault(e => e.EmployeeId == adminLog.EmployeeId);
            AdminLog log = new AdminLog
            {
                EmployeeId = adminLog.EmployeeId,
                OperatDetail = adminLog.OperatDetail,
                Operater = employee.User.NickName,
                OperationTime = DateTime.Now,
                Result = adminLog.Result
            };
            data.AdminLogs.Add(log);
            data.SaveChanges();
        }

        public void Dispose()
        {
            data.Dispose();
        }
    }
}
